package com.atguigu.gmall.product.service.impl;


import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.product.mapper.BaseAttrInfoMapper;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseAttrInfoServiceImpl extends ServiceImpl<BaseAttrInfoMapper, BaseAttrInfo> implements BaseAttrInfoService {


    @Autowired
    BaseAttrInfoMapper baseAttrInfoMapper;

    /**
     * 根据分类id获取平台属性
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     * select * from base_attr_info (category_id = 1 and category_level=1) or (category_id=20 and category_level=2)
     *                            or(category_id = 61 and category_level=3)
     */
    @Override
    public List<BaseAttrInfo> getBaseAttrInfoByCategoryId(Long category1Id, Long category2Id, Long category3Id) {

        QueryWrapper<BaseAttrInfo> queryWrapper = new QueryWrapper<>();
        if (!category1Id.equals(0)){
            //void accept(T var1);
            queryWrapper.or((w)->{
                w.eq("category_id",category1Id);
                w.eq("category_level",1);
            });
        }

        if (!category2Id.equals(0)){
            queryWrapper.or((w)->{
                w.eq("category_id",category2Id);
                w.eq("category_level",2);
            });
        }

        if (!category3Id.equals(0)){
            queryWrapper.or((w)->{
                w.eq("category_id",category3Id);
                w.eq("category_level",3);
            });
        }

        List<BaseAttrInfo> list = baseMapper.selectList(queryWrapper);

        // 遍历list  获取BaseAttrInfo的主键id
        for (BaseAttrInfo info : list) {
            Long id = info.getId();
            QueryWrapper<BaseAttrValue> baseAttrValueQueryWrapper = new QueryWrapper<>();
            baseAttrValueQueryWrapper.eq("attr_id",id);

        }



        return list;
    }




}
